package org.jeecg.modules.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiProcessinstanceCreateRequest;
import com.dingtalk.api.request.OapiProcessinstanceGetRequest;
import com.dingtalk.api.request.OapiUserGetRequest;
import com.dingtalk.api.request.OapiUserGetUseridByUnionidRequest;
import com.dingtalk.api.response.OapiProcessinstanceCreateResponse;
import com.dingtalk.api.response.OapiProcessinstanceGetResponse;
import com.dingtalk.api.response.OapiUserGetResponse;
import com.dingtalk.api.response.OapiUserGetUseridByUnionidResponse;
import com.taobao.api.ApiException;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.api.OverrideCheck;
import org.jeecg.modules.config.Constant;
import org.jeecg.modules.config.URLConstant;
import org.jeecg.modules.entity.ProjectProfessorInfo;
import org.jeecg.modules.mapper.DiyProfessorInfoMapper;
import org.jeecg.modules.model.ProcessInstanceInputVO;
import org.jeecg.modules.service.CallbackService;
import org.jeecg.modules.temporary.entity.DiyTemporaryApplicantInfo;
import org.jeecg.modules.util.AccessTokenUtil;

import org.jeecg.modules.util.ConstantDiy;
import org.jeecg.modules.vo.ProfessorChoose;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * @author ZhangHaoyu
 * @description
 * @date 2020/6/1 14:23
 */
@Service
public class CallbackServiceImpl implements CallbackService{

    @Autowired
    DiyProfessorInfoMapper diyProfessorInfoMapper;

    @Override
    public String selUserIdByUnionid(String username) {
        try {
            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getUseridByUnionid");
            OapiUserGetUseridByUnionidRequest req = new OapiUserGetUseridByUnionidRequest();

            req.setUnionid(username);
            req.setHttpMethod("GET");
            OapiUserGetUseridByUnionidResponse rsp = client.execute(req, AccessTokenUtil.getToken());
            System.out.println(rsp.getBody());
            return rsp.getBody();
        } catch (ApiException e) {
            e.printStackTrace();
        }
         return null;
    }

    @Override
    public String getInfoById(String processInstanceId) {
        try {
            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/get");
            OapiProcessinstanceGetRequest req = new OapiProcessinstanceGetRequest();
            // 审批实例id
            req.setProcessInstanceId(processInstanceId);
            OapiProcessinstanceGetResponse rsp = client.execute(req, AccessTokenUtil.getToken());
            return rsp.getBody();
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return null;
    }


    @Override
    public String sendToDingTalk(DiyTemporaryApplicantInfo diyTemporaryApplicantInfo, String userid) {

        // 姓名
        String professorName = diyTemporaryApplicantInfo.getProfessorName();
        // 性别
        Integer professorSex = diyTemporaryApplicantInfo.getProfessorSex();

        // 出生日期
        Date professorBirthday = diyTemporaryApplicantInfo.getProfessorBirthday();
        // 转换一下日期的格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String birthday = sdf.format(professorBirthday);

        // 照片
        byte[] professorPhoto = diyTemporaryApplicantInfo.getProfessorPhoto();
        String img = new String(professorPhoto);
        diyTemporaryApplicantInfo.setProfessorPhotoString(img);

        // 申请表照片
        byte[] professorInfoPhoto = diyTemporaryApplicantInfo.getProfessorInfoPhoto();
        String infoImg = new String(professorInfoPhoto);
        diyTemporaryApplicantInfo.setProfessorInfoPhotoString(infoImg);

        //身份证复印件
        byte[] professorId = diyTemporaryApplicantInfo.getProfessorId();
        String IDImage=new String(professorId);
        diyTemporaryApplicantInfo.setProfessorIdString(IDImage);

        //其他证明专业能力的材料
        byte[] professorother = diyTemporaryApplicantInfo.getProfessorOther();
        String OtherImage=new String(professorother);
        diyTemporaryApplicantInfo.setProfessorOtherString(OtherImage);

        //专业资格职业证书复印件
        byte[] professorQualification = diyTemporaryApplicantInfo.getProfessorQualification();
        String quailficationImage=new String(professorQualification);
        diyTemporaryApplicantInfo.setProfessorQualificationString(quailficationImage);

        //个人工作简历
        byte[] professorResume = diyTemporaryApplicantInfo.getProfessorResume();
        String ResumeImage=new String(professorResume);
        diyTemporaryApplicantInfo.setProfessorIdString(ResumeImage);

        //学历、学位证书复印件
        byte[] professorDegreeImage = diyTemporaryApplicantInfo.getProfessorDegreeImage();
        String DegreeImage=new String(professorDegreeImage);
        diyTemporaryApplicantInfo.setProfessorIdString(DegreeImage);

        //个人承诺书
        byte[] professorCommitment = diyTemporaryApplicantInfo.getProfessorCommitment();
        String CommitmentImage=new String(professorCommitment);
        diyTemporaryApplicantInfo.setProfessorIdString(CommitmentImage);

        // 毕业学校
        String professorSchool = diyTemporaryApplicantInfo.getProfessorSchool();
        // 所学专业
        String professorMajor = diyTemporaryApplicantInfo.getProfessorMajor();
        // 毕业时间
        Date professorGraduateDate = diyTemporaryApplicantInfo.getProfessorGraduateDate();
        // 转换格式
        String graduate = sdf.format(professorGraduateDate);
        // 学历
        String professorEducationBackground = diyTemporaryApplicantInfo.getProfessorEducationBackground();
        // 学位
        String professorDegree = diyTemporaryApplicantInfo.getProfessorDegree();
        // 工作单位
        String professorWorkUnit = diyTemporaryApplicantInfo.getProfessorWorkUnit();
        // 通讯地址
        String professorAddress = diyTemporaryApplicantInfo.getProfessorAddress();
        // 申报类别
        String professorDeclareCategory = diyTemporaryApplicantInfo.getProfessorDeclareCategory();
        // 根据id查找

        // 职务
        String professorPosition = diyTemporaryApplicantInfo.getProfessorPosition();
        // 参加工作时间
        Date professorBeginWork = diyTemporaryApplicantInfo.getProfessorBeginWork();
        // 转换格式
        String beginWork = sdf.format(professorBeginWork);
        // 技术职称
        String professorTitle = diyTemporaryApplicantInfo.getProfessorTitle();
        // 从事专业
        String professorWorkMajor = diyTemporaryApplicantInfo.getProfessorWorkMajor();
        // 从事专业时间
        Date professorMajorDate = diyTemporaryApplicantInfo.getProfessorMajorDate();
        // 转换格式
        String majorDate = sdf.format(professorMajorDate);
        // 身份证号
        String professorIdentity = diyTemporaryApplicantInfo.getProfessorIdentity();
        // 家庭地址
        String professorHomeAddress = diyTemporaryApplicantInfo.getProfessorProjectIntroduce();
        // 健康状态
        String professorHealth = diyTemporaryApplicantInfo.getProfessorHealth();
        // 办公电话
        String professorOfficeTel = diyTemporaryApplicantInfo.getProfessorOfficeTel();
        // 手机号
        String professorPhone = diyTemporaryApplicantInfo.getProfessorPhone();
        // 参与项目简介
        String professorProjectIntroduce = diyTemporaryApplicantInfo.getProfessorProjectIntroduce();
        // 主管部门意见;
        String professorLeadMsg = diyTemporaryApplicantInfo.getProfessorLeadMsg();
        // 行政审批局
        String professorApproveMsg = diyTemporaryApplicantInfo.getProfessorApproveMsg();
        // 调用其他方法获得相对应的数据
        // 获取毕业院校名称
//        String sProfessorSchool = diyProfessorInfoMapper.selSchoolById(professorSchool);
//        System.out.println("sProfessorSchool = " + sProfessorSchool.length());
        // 获取家庭地址名称 ？
        // 获取申报类别名称
        String[] ids = professorDeclareCategory.split(",");
        String names = "";
        int i = 1;
        for (String id : ids) {
            // 每一个id都是一个申报类型的代号，获取类型名字
            String name = diyProfessorInfoMapper.selDictNameById(id);
            names += name;
            i++;
            //如果不是最后一位，都分隔开，
            if(i<=ids.length){
                names = names +",";
            }
        }

        //获取专业名称
        String majorName = diyProfessorInfoMapper.selMajorNameById(professorMajor);


        // 放入钉钉表单中
        ProcessInstanceInputVO processInstance = new ProcessInstanceInputVO();
        processInstance.setOriginatorUserId(userid);
        processInstance.setDeptId(1L);

        ProcessInstanceInputVO.TextForm textForms1 = new ProcessInstanceInputVO.TextForm();
        textForms1.setName(ConstantDiy.D_NAME);
        textForms1.setValue(professorName);
        ProcessInstanceInputVO.TextForm textForm2 = new ProcessInstanceInputVO.TextForm();
        textForm2.setName(ConstantDiy.D_SEX);
        textForm2.setValue(professorSex==1?"男":"女");
        ProcessInstanceInputVO.TextForm textForm25 = new ProcessInstanceInputVO.TextForm();
        textForm25.setName(ConstantDiy.D_ADDRESS);
        textForm25.setValue(professorAddress);
        ProcessInstanceInputVO.TextForm textForm3 = new ProcessInstanceInputVO.TextForm();
        textForm3.setName(ConstantDiy.D_BIRTHDAY);
        textForm3.setValue(birthday);
        ProcessInstanceInputVO.TextForm textForm4 = new ProcessInstanceInputVO.TextForm();
        textForm4.setName(ConstantDiy.D_SCHOOL);
        textForm4.setValue(professorSchool.trim());
        ProcessInstanceInputVO.TextForm textForm5 = new ProcessInstanceInputVO.TextForm();
        textForm5.setName(ConstantDiy.D_PHONE);
        textForm5.setValue(professorPhone);
        ProcessInstanceInputVO.TextForm textForm6 = new ProcessInstanceInputVO.TextForm();
        textForm6.setName(ConstantDiy.D_PROJECT);
        textForm6.setValue(professorProjectIntroduce);
        ProcessInstanceInputVO.TextForm textForm7 = new ProcessInstanceInputVO.TextForm();
        textForm7.setName(ConstantDiy.D_PHOTO);
        textForm7.setValue("[\""+ConstantDiy.IMG_URL_FONT+img+"\"]");
        //[\"http://29258950la.zicp.vip/jeecg-boot/sys/common/static/" +img+"\"]
        ProcessInstanceInputVO.TextForm textForm8 = new ProcessInstanceInputVO.TextForm();
        textForm8.setName(ConstantDiy.D_MAJOR);
        textForm8.setValue(majorName);

        ProcessInstanceInputVO.TextForm textForm9 = new ProcessInstanceInputVO.TextForm();
        textForm9.setName(ConstantDiy.D_GRADUATE);
        textForm9.setValue(graduate);

        ProcessInstanceInputVO.TextForm textForm10 = new ProcessInstanceInputVO.TextForm();
        textForm10.setName(ConstantDiy.D_EDUCATIONBACKGROUND);
        textForm10.setValue(professorEducationBackground);
        ProcessInstanceInputVO.TextForm textForm11 = new ProcessInstanceInputVO.TextForm();
        textForm11.setName(ConstantDiy.D_DEGREE);
        textForm11.setValue(professorDegree);
        ProcessInstanceInputVO.TextForm textForm12 = new ProcessInstanceInputVO.TextForm();
        textForm12.setName(ConstantDiy.D_WORKUNIT);
        textForm12.setValue(professorWorkUnit);
        ProcessInstanceInputVO.TextForm textForm13 = new ProcessInstanceInputVO.TextForm();
        textForm13.setName(ConstantDiy.D_DECLARECATEGORY);
        textForm13.setValue(names);
        ProcessInstanceInputVO.TextForm textForm14 = new ProcessInstanceInputVO.TextForm();
        textForm14.setName(ConstantDiy.D_POSITION);
        textForm14.setValue(professorPosition);
        ProcessInstanceInputVO.TextForm textForm15 = new ProcessInstanceInputVO.TextForm();
        textForm15.setName(ConstantDiy.D_BEGINWORK);
        textForm15.setValue(beginWork);
        ProcessInstanceInputVO.TextForm textForm16 = new ProcessInstanceInputVO.TextForm();
        textForm16.setName(ConstantDiy.D_TITLE);
        textForm16.setValue(professorTitle);
        ProcessInstanceInputVO.TextForm textForm17 = new ProcessInstanceInputVO.TextForm();
        textForm17.setName(ConstantDiy.D_WORKMAJOR);
        textForm17.setValue(professorWorkMajor);
        ProcessInstanceInputVO.TextForm textForm18 = new ProcessInstanceInputVO.TextForm();
        textForm18.setName(ConstantDiy.D_MAJORDATE);
        textForm18.setValue(majorDate);
        ProcessInstanceInputVO.TextForm textForm19 = new ProcessInstanceInputVO.TextForm();
        textForm19.setName(ConstantDiy.D_IDENTITY);
        textForm19.setValue(professorIdentity);
        ProcessInstanceInputVO.TextForm textForm20 = new ProcessInstanceInputVO.TextForm();
        textForm20.setName(ConstantDiy.D_HOMEADDRESS);
        textForm20.setValue(professorHomeAddress);
        ProcessInstanceInputVO.TextForm textForm21 = new ProcessInstanceInputVO.TextForm();
        textForm21.setName(ConstantDiy.D_HEALTH);
        textForm21.setValue(professorHealth);
        ProcessInstanceInputVO.TextForm textForm22 = new ProcessInstanceInputVO.TextForm();
        textForm22.setName(ConstantDiy.D_OFFICE);
        textForm22.setValue(professorOfficeTel);
        ProcessInstanceInputVO.TextForm textForm23 = new ProcessInstanceInputVO.TextForm();
        textForm23.setName(ConstantDiy.D_LEADMSG);
        textForm23.setValue(diyTemporaryApplicantInfo.getProfessorLeadMsg());
//        行政局审批意见
//        ProcessInstanceInputVO.TextForm textForm24 = new ProcessInstanceInputVO.TextForm();
//        textForm24.setName(ConstantDiy.D_APPROVEMSG);
//        textForm24.setValue(professorApproveMsg);
        ProcessInstanceInputVO.TextForm textForm24 = new ProcessInstanceInputVO.TextForm();
        textForm24.setName(ConstantDiy.D_INFOPHOTO);
        textForm24.setValue("[\""+ConstantDiy.IMG_URL_FONT+infoImg+"\"]");

        ProcessInstanceInputVO.TextForm textForm26 = new ProcessInstanceInputVO.TextForm();
        textForm26.setName(ConstantDiy.D_ID);
        textForm26.setValue("[\""+ConstantDiy.IMG_URL_FONT+IDImage+"\"]");

        ProcessInstanceInputVO.TextForm textForm27 = new ProcessInstanceInputVO.TextForm();
        textForm27.setName(ConstantDiy.D_DEGREEIMAGE);
        JSONArray array = new JSONArray();
        String[] split=DegreeImage.split(",");
        for(String string : split){
            array.add(ConstantDiy.IMG_URL_FONT+string);
        }
        textForm27.setValue(array.toJSONString());

        ProcessInstanceInputVO.TextForm textForm28 = new ProcessInstanceInputVO.TextForm();
        textForm28.setName(ConstantDiy.D_QUALIFICATION);
        JSONArray array02 = new JSONArray();
        String[] split02=quailficationImage.split(",");
        for(String string : split02){
            array02.add(ConstantDiy.IMG_URL_FONT+string);
        }
        textForm28.setValue(array02.toJSONString());

        ProcessInstanceInputVO.TextForm textForm29 = new ProcessInstanceInputVO.TextForm();
        textForm29.setName(ConstantDiy.D_OTHER);
        JSONArray array03 = new JSONArray();
        String[] split03=OtherImage.split(",");
        for(String string : split03){
            array03.add(ConstantDiy.IMG_URL_FONT+string);
        }
        textForm29.setValue(array03.toJSONString());

        ProcessInstanceInputVO.TextForm textForm30 = new ProcessInstanceInputVO.TextForm();
        textForm30.setName(ConstantDiy.D_RESUME);
        JSONArray array04 = new JSONArray();
        String[] split04=ResumeImage.split(",");
        for(String string : split04){
            array04.add(ConstantDiy.IMG_URL_FONT+string);
        }
        textForm30.setValue(array04.toJSONString());

        ProcessInstanceInputVO.TextForm textForm31 = new ProcessInstanceInputVO.TextForm();
        textForm31.setName(ConstantDiy.D_COMMITMENT);
        textForm31.setValue("[\""+ConstantDiy.IMG_URL_FONT+CommitmentImage+"\"]");

        ArrayList<ProcessInstanceInputVO.TextForm> textForms = new ArrayList<>();
        textForms.add(textForms1);
        textForms.add(textForm2);
        textForms.add(textForm3);
        textForms.add(textForm4);
        textForms.add(textForm5);
        textForms.add(textForm6);
        textForms.add(textForm7);
        textForms.add(textForm8);
        textForms.add(textForm9);
        textForms.add(textForm10);
        textForms.add(textForm11);
        textForms.add(textForm12);
        textForms.add(textForm13);
        textForms.add(textForm14);
        textForms.add(textForm15);
        textForms.add(textForm16);
        textForms.add(textForm17);
        textForms.add(textForm18);
        textForms.add(textForm19);
        textForms.add(textForm20);
        textForms.add(textForm21);
        textForms.add(textForm22);
        textForms.add(textForm23);
        textForms.add(textForm24);
        textForms.add(textForm25);
        textForms.add(textForm26);
        textForms.add(textForm27);
        textForms.add(textForm28);
        textForms.add(textForm29);
        textForms.add(textForm30);
        textForms.add(textForm31);

        processInstance.setTextForms(textForms);


        DefaultDingTalkClient client = new DefaultDingTalkClient(URLConstant.URL_PROCESSINSTANCE_START);
        OapiProcessinstanceCreateRequest request = new OverrideCheck();

        request.setProcessCode(Constant.PROCESS_CODE);

        request.setFormComponentValues(processInstance.generateForms());

        request.setOriginatorUserId(processInstance.getOriginatorUserId());
        request.setDeptId(processInstance.getDeptId());

        OapiProcessinstanceCreateResponse response = null;
        try {
            response = client.execute(request, AccessTokenUtil.getToken());
            System.out.println(response);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        /*以上是钉钉表单*/

        // 返回审批实例id
        return response.getProcessInstanceId();
    }
    @Override
    public String sendProfessorChooseToDingTalk(ProfessorChoose professorChoose, String originatorUserId, String approvers) {

        //项目编码
        String projectId = professorChoose.getProjectId();
        // 项目名称
        String projectName = professorChoose.getProjectName();
        // 项目类型
        String projectType = professorChoose.getProjectType();
        //项目开始时间
        Date professorJoinMeetingTime = professorChoose.getProfessorJoinMeetingTime();
        String date= DateUtils.formatTime(professorJoinMeetingTime);
        //项目开始地点
        String professorJoinMeetingAddress = professorChoose.getProfessorJoinMeetingAddress();
        // 项目来源
        String projectFrom = professorChoose.getProjectFrom();
        // 预计评审时长
        String projectExpectTime = professorChoose.getProjectExpectTime();
        // 项目金额
        String projectAmount = professorChoose.getProjectAmount();


        // 放入钉钉表单中
        ProcessInstanceInputVO processInstance = new ProcessInstanceInputVO();
        processInstance.setOriginatorUserId(originatorUserId);
        processInstance.setApprovers(approvers);
        processInstance.setDeptId(1L);
        ProcessInstanceInputVO.TextForm textForms0 = new ProcessInstanceInputVO.TextForm();
        textForms0.setName("项目编码");
        textForms0.setValue(projectId);
        ProcessInstanceInputVO.TextForm textForms1 = new ProcessInstanceInputVO.TextForm();
        textForms1.setName("项目名称");
        textForms1.setValue(projectName);
        ProcessInstanceInputVO.TextForm textForms2 = new ProcessInstanceInputVO.TextForm();
        textForms2.setName("项目类型");
        textForms2.setValue(projectType);
        ProcessInstanceInputVO.TextForm textForms3 = new ProcessInstanceInputVO.TextForm();
        textForms3.setName("日期");
        textForms3.setValue(date);
        ProcessInstanceInputVO.TextForm textForms4 = new ProcessInstanceInputVO.TextForm();
        textForms4.setName("地点");
        textForms4.setValue(projectFrom);
        ProcessInstanceInputVO.TextForm textForms5 = new ProcessInstanceInputVO.TextForm();
        textForms5.setName("项目来源");
        textForms5.setValue(professorJoinMeetingAddress);
        ProcessInstanceInputVO.TextForm textForms6 = new ProcessInstanceInputVO.TextForm();
        textForms6.setName("预计评审时长");
        textForms6.setValue(projectExpectTime);
        ProcessInstanceInputVO.TextForm textForms7 = new ProcessInstanceInputVO.TextForm();
        textForms7.setName("项目金额");
        textForms7.setValue(projectAmount);

        ArrayList<ProcessInstanceInputVO.TextForm> textForms = new ArrayList<>();
        textForms.add(textForms0);
        textForms.add(textForms1);
        textForms.add(textForms2);
        textForms.add(textForms3);
        textForms.add(textForms4);
        textForms.add(textForms5);
        textForms.add(textForms6);
        textForms.add(textForms7);
        //将textForms添加到textForms中
        processInstance.setTextForms(textForms);
        DefaultDingTalkClient client = new DefaultDingTalkClient(URLConstant.URL_PROCESSINSTANCE_START);
        OapiProcessinstanceCreateRequest request = new OverrideCheck();

        request.setProcessCode("PROC-3FAC300E-1B01-423C-BD08-8FC18B96E07E");

        request.setFormComponentValues(processInstance.generateForms());

        request.setOriginatorUserId(processInstance.getOriginatorUserId());
        request.setDeptId(processInstance.getDeptId());
        request.setApprovers(processInstance.getApprovers());
        OapiProcessinstanceCreateResponse response = null;
        try {
            response = client.execute(request, AccessTokenUtil.getToken());
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return response.getProcessInstanceId();
    }

    @Override
    public String getUnionIdByUserId(String originator_userid) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/get");
        OapiUserGetRequest req = new OapiUserGetRequest();
        req.setUserid(originator_userid);
        req.setHttpMethod("GET");
        OapiUserGetResponse rsp = null;
        try {
            rsp = client.execute(req,AccessTokenUtil.getToken());
            JSONObject object = JSONObject.parseObject(rsp.getBody());
            // 得到unionid（username）
            String unionid = object.getString("unionid");
            // 获得Id
            return unionid;
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public String getUidByUserId(String originator_userid) {
        String unionId = getUnionIdByUserId(originator_userid);
        return diyProfessorInfoMapper.getIdByUnionId(unionId);
}


    @Override
    public String getUnionIdByUserIdFromDB(String originator_userid) {
        return diyProfessorInfoMapper.getUnionIdByUserId(originator_userid);
    }

    @Override
    public void sendLeaveCauseToDing(JSONObject jsonObject) {
        // 获取userid
        String userId = jsonObject.getString("userId");
        // 获取projectId
        String projectId = jsonObject.getString("projectId");
        // 获取请假原因
        String leaveCause = jsonObject.getString("leaveCause");

        // 构建表单发送到钉钉上
        ProcessInstanceInputVO processInstance = new ProcessInstanceInputVO();
        processInstance.setOriginatorUserId(userId);
        processInstance.setDeptId(1L);
        ProcessInstanceInputVO.TextForm textForms1 = new ProcessInstanceInputVO.TextForm();
        textForms1.setName("项目编号");
        textForms1.setValue(projectId);
        ProcessInstanceInputVO.TextForm textForms2 = new ProcessInstanceInputVO.TextForm();
        textForms2.setName("申请理由");
        textForms2.setValue(leaveCause);
        ArrayList<ProcessInstanceInputVO.TextForm> textForms = new ArrayList<>();
        textForms.add(textForms1);
        textForms.add(textForms2);
        processInstance.setTextForms(textForms);
        DefaultDingTalkClient client = new DefaultDingTalkClient(URLConstant.URL_PROCESSINSTANCE_START);
        OapiProcessinstanceCreateRequest request = new OverrideCheck();
        request.setProcessCode(Constant.SUDDEN_LEAVE_PROCESS_CODE);
        request.setDeptId(processInstance.getDeptId());
        request.setFormComponentValues(processInstance.generateForms());

        request.setOriginatorUserId(processInstance.getOriginatorUserId());
        OapiProcessinstanceCreateResponse response = null;
        try {
            response = client.execute(request, AccessTokenUtil.getToken());
        } catch (ApiException e) {
            e.printStackTrace();
        }
    }


}
